package com.winning.sx.microframework.common.support;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.map.HashedMap;

import java.io.IOException;
import java.util.Map;

/**
 * @author wangj_envy
 * @date 2019年6月6日13:26:03
 */
public class DataMap {

    private static ObjectMapper objectMapper = new ObjectMapper();

    public static Map<String,Object> map(){
        return new HashedMap();
    }

    /**
     * 测试使用
     * @return
     */
    public static Map<String,Object> mockOrigin(){
        Map<String, Object> map = map();
        map.put("from","origin");
        map.put("msg","mock success");
        return map;
    }

    /**
     * 测试使用
     * @return
     */
    public static Map<String,Object> mockWinning(){
        Map<String, Object> map = map();
        map.put("from","winning");
        map.put("msg","mock success");
        return map;
    }

    /**
     * 转化data成为hashmap
     * @param data
     * @return
     * @throws IOException 参数格式有误
     */
    public static Map<String,Object> transfrom(String data) throws IOException {
        Map map = objectMapper.readValue(data, Map.class);
        return map;
    }

}
